<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<img src="auth.png" />
		<title>Google Calendar</title>
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript">
			
			google.load("gdata", "1");
			google.setOnLoadCallback(setupMyService);

			var myService;

			function logMeIn() {
				alert("logMeIn()");
				scope = "https://www.google.com/calendar/feeds/martin.j.johansson@gmail.com";
				if (google.accounts.user.checkLogin(scope)) {
					alert('Authenticated!');
				} else {
					alert('Not authenticated!');
					google.accounts.user.login(scope);
				}
			}

			function logMeOut() {
				alert("logMeOut()");
				google.accounts.user.logout();
			}

			function setupMyService() {
				alert("setupMyService()");
				myService = new google.gdata.calendar.CalendarService('exampleCo-exampleApp-1');
			}

			function createMyEvent() {
				alert("createMyEvent()");
				// The default "private/full" feed is used to insert event to the 
				// primary calendar of the authenticated user
				var feedUri = 'https://www.google.com/calendar/feeds/martin.j.johansson@gmail.com/private/full';

				// Create an instance of CalendarEventEntry representing the new event
				var entry = new google.gdata.calendar.CalendarEventEntry();

				// Set the title of the event
				entry.setTitle(google.gdata.Text.create('JS-Client: insert event'));

				// Create a When object that will be attached to the event
				var when = new google.gdata.When();

				// Set the start and end time of the When object
				var startTime = google.gdata.DateTime.fromIso8601("2011-08-05T09:00:00.000-00:00");
				var endTime = google.gdata.DateTime.fromIso8601("2011-08-05T10:00:00.000-00:00");
				when.setStartTime(startTime);
				when.setEndTime(endTime);

				// Add the When object to the event 
				entry.addTime(when);

				// The callback method that will be called after a successful insertion from insertEntry()
				var callback = function(result) {
				  alert("event created!");
				};

				// Error handler will be invoked if there is an error from insertEntry()
				var handleError = function(e) {
				  alert(e.cause ? e.cause.statusText : e.message);
				};

				// Submit the request using the calendar service object
				myService.insertEntry(feedUri, entry, callback, 
					handleError, google.gdata.calendar.CalendarEventEntry);
			}
		</script>
	</head>
	<body>
		<FORM NAME="menyn">
			Add Google Calendar entry
			<SELECT NAME="menuProject">
				<OPTION VALUE="musikfiler/musik.mp3">CDP+</OPTION>
				<OPTION VALUE="bild.gif">ANPCS</OPTION>
			</SELECT>
			<SELECT NAME="menuStart">
				<OPTION VALUE="musikfiler/musik.mp3">08:00</OPTION>
				<OPTION VALUE="13">13:00</OPTION>
				<OPTION VALUE="17">17:00</OPTION>
			</SELECT>
			<SELECT NAME="menuTime">
				<OPTION VALUE="1">1</OPTION>
				<OPTION VALUE="musikfiler/musik.mp3">2</OPTION>
				<OPTION VALUE="bild.gif">4</OPTION>
			</SELECT>
			<!--This is one of many scripts which are available at:     *---
			//--http://www.JavaScript.nu/javascript                     *---
			//--This script is FREE, but you MUST let these lines       *---
			//--remain if you use this script.                          *---
			-->
			<INPUT type="button" value="Log In" onclick="logMeIn()" />
			<INPUT type="button" value="Log Out" onclick="logMeOut()" />
			<INPUT type="button" value="Create Event" onclick="createMyEvent()" />
		</FORM>

	</body>
</html>